<template>
  <div>
    <!-- 特殊车辆包修期维护 -->
    <!-- 搜索 -->
    <TopFilter ref="TopFilterss" :list="topFilterInit" :cols="3" labelWidth="90" @filterChange="changeHandle"></TopFilter>
    <!-- table -->
    <FilterTable
      ref="table"
      :columns="columns"
      :params="fetchParams"
      :fetchapi="fetchapi"
      :datakey="'records'"
      :onColumnsChange="(columns) => (this.columns = columns)"
      :onRowSelectChange="selectChange"
      :isSelectColumn="false"
      height="auto"
    >
      <template slot="controls" slot-scope="props">
        <multiuse-button size="small" type="primary" icon="el-icon-plus" @click="add()">新增</multiuse-button>
        <multiuse-button type="primary" @click="downloadTemplate()">导出</multiuse-button>
      </template>
    </FilterTable>

    <BaseDialog :visible.sync="visibleAdd" :title="'特殊车辆包修期维护新增'" width="850px" destroyOnClose :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
      <AddForm @close="closeAdd" @save="saveAdd"></AddForm>
    </BaseDialog>
    <BaseDialog :visible.sync="emitVisible" title="特殊车辆包修期维护信息" width="850px" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <editForm @close="emitCloseHandle" @save="emitChange" :rowData="rowData" :spId = "spId" :type = "type"/>
    </BaseDialog>

    <BaseDialog :visible.sync="showImport" icon="el-icon-upload" :closable="false" title="导入" width="800px" destroyOnClose :containerStyle="{ height: 'calc(100% - 120px)', overflow: 'auto', paddingBottom: '60px' }">
      <importExcel @close="showImport = false" @importclose="editsave()" url="/api/cms_claimfac/rPSelfPt/importExcel"/>
    </BaseDialog>
  </div>
</template>
<script>
import { exportExcelFile } from '@/utils/index';
import { getListByPage,exportExcel,exporturl } from '@/api/claim/factory/SpecialUserWarrantyMaintain';
import AddForm from './AddForm.vue';
import editForm from './editForm.vue';
import { dictionary } from '@/utils/dictMixin';
import moment  from 'moment';
import importExcel from '@/pages/claimDemage/tools/importExcel.vue';
export default {
  mixins: [dictionary],
  components: {
    AddForm,
    editForm,
    importExcel
  },
  data() {
    return {
      visible: false,
      emitVisible: false,
      visibleDrawer: false,
      showImport: false,
      infoId: null,
      fetchapi: getListByPage,
      topFilterInit: this.topFilterInitFun(),
      flterValue: {}, //参数
      columns: this.creatHeader(),
      fetchParams: {}, //ipa 接口
      selectedRows: [], //选中经销商
      rowData: {},
      type:'',
      spId:'',
      visibleAdd: false
    };
  },
  created() {
    let val = this.selectedRows;
    console.log("val===",val)
    console.log("columns===",this.columns)
  },
  methods: {
    //选中
    selectChange(rows) {
      this.selectedRows = rows;
      console.log("selectedRows==",this.selectedRows);
    },
    close() {
      this.visible = false;
    },
    chooseOrderNo() {
      this.visible = true;
    },
    save(obj) {
      this.topFilterInit.find((x) => x.fieldName == 'model').initialValue = obj[0].address;
      this.visible = false;
    },
    // Excel更新导入
    showImportFun() {
      this.showImport = true;
    },
    editsave() {
      this.showImport = false;
      this.fetchParams = { ...this.fetchParams };
    },
    add() {
      this.visibleAdd = true;
    },
    closeAdd() {
      this.visibleAdd = false;
    },
    emitFun(data,type) {
      this.type = type;
      this.rowData = data;
      this.emitVisible = true;
    },
     emitCloseHandle() {
       this.emitVisible = false;
       this.fetchParams = { ...this.fetchParams };
     },
    emitChange() {
      this.emitVisible = true;
      this.fetchParams = { ...this.fetchParams };
    },
    saveAdd() {
      this.visibleAdd = false;
      this.fetchParams = { ...this.fetchParams };
    },
    //搜索获取数据
    changeHandle(val) {
      this.fetchParams = Object.assign({}, this.fetchParams, val);
      console.log(val);
    },
    //导出
    async downloadTemplate() {
      let [err, formData] = await this.$refs.TopFilterss.GET_FORM_DATA();
      console.log('formData',formData)
      if(!err){
        exportExcel(formData).then(res => {
          exportExcelFile(res.data, '特殊车辆包修期维护信息');
        });
      }
    },
    //搜索数据
    topFilterInitFun() {
      return [
        {
          type: 'INPUT',
          label: '分组名称',
          fieldName: 'groupName',
          placeholder: '请输入分组名称...',
          initialValue: ''
        },
        {
          type: 'SELECT',
          label: '状态',
          fieldName: 'vpStatus',
          placeholder: '请输入状态...',
          itemList: [{text: '启用', value: 1}, {text: '停用', value: 0}]
        }
      ];
    },
    //table表头和数据源
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          fixed: 'left',
          sorter: true,
          render: (props) => {
            return <span>{props.row.index + 1}</span>;
          },
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 100,
          render: (props, h) => {
            return (
              <div style="text-align:center">
                <multiuse-button size="mini" type="text" onClick={() => this.emitFun(props.row)}>
                  编辑
                </multiuse-button>
                <multiuse-button size="mini" type="text" onClick={() => this.emitFun(props.row,"show")}>
                  明细
                </multiuse-button>
              </div>
            );
          },
        },
        { title: '分组代码', dataIndex: 'groupCode', sorter: true },
        { title: '分组名称', dataIndex: 'groupName', sorter: true },
        { title: '状态',dataIndex: 'statusStr', sorter: true },
        { title: '创建人', dataIndex: 'createdBy', sorter: true },
        { title: '分组创建时间',dataIndex: 'createdAt', sorter: true
        ,render: props => {
            return <span>{moment(props.row.createdAt).format('YYYY-MM-DD hh:mm:ss')}</span>;
          }},
        { title: '修改人', dataIndex: 'updatedBy', sorter: true },
        { title: '分组修改时间',dataIndex: 'updatedAt', sorter: true ,render: props => {
            return <span>{moment(props.row.updatedAt).format('YYYY-MM-DD hh:mm:ss')}</span>;
          }}
      ];
    }
  }
};
</script>

<style lang="less" scoped></style>
